<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>编辑接待申请单</title>
	<#include "/common/resource.ftl">
	<script type="text/javascript">
        var getStepUsers = function() {
            <#if !((params.id)??)>
                $.ajaxRequest({
                    url: '${params.contextPath}/web/workflowStep/getNextStepUsers',
                    data: {workflowDefineId: "${params.defineId!}", stepNum: 0},
                    success: function (data) {
                        if (!data.success) {
                            $.message(data.message);
                            return;
                        }
                        var list = data.data, stepName = "", options = "";
                        for (var i = 0; i < list.length; i ++) {
                            options += '<option value="{userId}">--{userName}--</option>'.format(list[i]);
                            stepName = list[i].stepName;
                        }
                        $('[name="nextStepName"]').val(stepName);
                        $('[name="nextStepUserId"]').append(options);
                    }
                });
            </#if>
        };

		$(function () {
			<#if (params.id)??>
				$.ajaxRequest({
					url: '${params.contextPath}/web/receiveApply/query',
					data: {id: "${params.id}"},
					success: function (data) {
						if (!data.success) {
							$.message(data.message);
							return;
						}
						var record = data.data;
						for (var key in record) {
							$("[name='" + key + "']").val(record[key]);
						}
						$('[name="receiveTime"]').val(record.receiveTimeStr + ":00");
                        getStepUsers();
					}
				});
            <#else>
                getStepUsers();
			</#if>
            $(".ajax-form2").unbind().submit(function () {
                try {
                    var form = $(this);
                    if (!form.valid()) {
                        $.message("验证不通过，无法提交表单");
                        return false;
                    }

                    form.formSubmit({
                        callBack:function (data) {
                            <#if !((params.id)??)>
                                history.go(-1);
                            </#if>
                        }
                    });
                } catch (e) {
                    console.log("表单提交错误：" + e);
                }
                return false;
            });
		});
	</script>
</head>
<body>
	<div class="ui-form" style="padding:20px;">
        <div class="layui-card">
            <div class="layui-card-header">接待申请单</div>
            <div class="layui-card-body">
                <form class="layui-form ajax-form2" action="${params.contextPath}/web/receiveApply/<#if (params.id)??>modify<#else>save</#if>" method="post">
                    <input type="hidden" name="id" value="${params.id!}" />
                    <input type="hidden" name="workflowDefineId" value="${params.defineId!}" />
                    <fieldset class="layui-elem-field">
                        <legend style="color:#FF5722;">申请单信息</legend>
                        <div class="layui-field-box">
                            <div class="layui-form-item">
                                <label class="layui-form-label">负责人<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="chargeUser" placeholder="请输入负责人" class="layui-input {required:true}"/>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">接待时间<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="receiveTime" placeholder="请输入接待时间" class="layui-input ui-datetime {required:true}" readonly/>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">接待对象<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="target" placeholder="请输入接待对象" class="layui-input {required:true}" maxlength="1000"/>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">行程安排<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <textarea name="schedule" class="layui-textarea {required:true}" maxlength="1000"></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">接待要求</label>
                                <div class="layui-input-block">
                                    <textarea name="require" class="layui-textarea" maxlength="1000"></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">类别<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <select name="category" class="layui-input {required:true}">
                                        <option value="">请选择</option>
                                        <option value="1">A类（会务类）</option>
                                        <option value="2">B类（参考观察类）</option>
                                        <option value="3">C类（公务接待）</option>
                                        <option value="4">D类（重要贵宾）</option>
                                        <option value="5">E类（大型活动）</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">接待费用<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="cost" placeholder="请输入接待费用" class="layui-input {required:true}"/>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">费用归属<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="costOwner" placeholder="请输入费用归属" class="layui-input {required:true}"/>
                                </div>
                            </div>
                        </div>
                    </fieldset>

                    <#if !((params.id)??)>
                        <fieldset class="layui-elem-field">
                            <legend style="color:#FF5722">流程审批信息</legend>
                            <div class="layui-field-box">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">下节点名称</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="nextStepName" class="layui-input" readonly/>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">选择处理人<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <select name="nextStepUserId" class="layui-input {required:true}">
                                            <option value="">--请选择下个节点处理人--</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </fieldset>
                    </#if>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <input type="submit" value="提交申请" class="layui-btn" />
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <#--end-->
	</div>
</body>

</html>
